<?php

/**
 * Class for Web Service routine handling
 *
 * @name Service
 * @author DiMoN
 * @copyright Dmitry Pavlov
 */

class Service
{
    /**
     * Forms Web service response XML Document
     *
     * @param string $result - Result of the operation
     * @param int $errorCode - Error code of the operation
     * @return string
     */
    public static function formResponseXML($result, $errorCode)
    {
        $response = new DOMDocument('1.0', 'UTF-8');
        $root = $response->createElement("response");
        $response->appendChild($root);

        $resultElement = $response->createElement("result", $result);
        $root->appendChild($resultElement);

        $errorElement = $response->createElement("error");
        $errorElement->setAttribute("code", $errorCode);
        $root->appendChild($errorElement);

        /*
         * $response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><result>" . $result . "</result><error code=\"" . $errorCode . "\"/></response>";
         * return $response;
         */

        return $response->saveXML();
    }
}
?>
